<template>
	<view class="order">
		<!-- tab 栏 -->
		<view class="serchView">
			<view class="serch">
				<!-- <image class="serchIconImage" src="/static/home/Vector.png" @tap.stop="searchIcon"></image> -->
				<u-search placeholder="搜索关键字检索" v-model="keyword" @custom="searchProtect" @search="searchProtect"></u-search>
				<!-- <input @input="searchProtect" adjust-position="false" class="serchInput" placeholder="" type="text" /> -->
			</view>
		</view>
		<!-- 列表 -->
		<view class="listBox">
			<scroll-view enable-back-to-top=true scroll-y="true" class="scrollHight"  :style="{height:height}"  @scrolltoupper="upper"
				@scrolltolower="lower" :refresher-enabled="true" :refresher-threshold="100"
				:refresher-triggered="isTriggered" @refresherrefresh="onRefresh" @refresherrestore="onRestore"
				@refresherpulling="onPulling">
				<view class="list" v-for="(item,index) in tabList" :key="index">
					<view class="" >
						<view class="code" style="font-size: 30rpx;display: flex;">
							<view class="title">序号：</view>
							<view class="content">{{item.id|| ''}}</view>
						</view>
						<view class="line"></view>
						<view class="code" style="font-size: 30rpx;display: flex;">
							<view class="title" >
								保护型号：
							</view>
							<view class="content">
								{{item.protectDeviceModel|| ''}}
							</view>
						</view>
						<view class="line"></view>
						<view class="code" style="font-size: 30rpx;display: flex;">
							<view class="title" >
								厂家名称：
							</view>
							<view class="content">
								{{item.manufacturer|| ''}}
							</view>
						</view>
						<view class="line"></view>
						<view class="code" style="font-size: 30rpx;display: flex;">
							<view class="title" >
								保护装置类型：
							</view>
							<view class="content">
								{{item.protectDeviceType|| ''}}
							</view>
						</view>
						<view class="line"></view>
						<view class="" style="font-size: 30rpx;">
							<view class=""  style="height: 60rpx;line-height: 80rpx;">
								原理图：
							</view>
							<view class="" style="display: flex;flex-wrap: wrap;">
								<view class="pic" v-for="(i,a) in item.principleImgUrl" :key="a" v-if="item.principleImgUrl.length != 0"> 
									<image :src="image+i" mode=""></image>
								</view>
							</view>
							
						</view>
					</view>
				</view>
				<!-- 提示栏 -->
				<!-- <view style="width: 100%; text-align: center; font-size: 28rpx; margin-top: 30rpx;">{{isText}}</view> -->
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import vvSelect from '@/pages/components/vv-select/vv-select.vue'
	export default {
		data() {
			return {
				image: this.$base.smallimgUrl,
				tabCurrent: 0,
				page: 1,
				tabList:[],
				isText: '',
				allList:[
					{
						name:'全部烟盒系列',
						id:1
					},
					{
						name:'芙蓉王系列',
						id:2
					}
				],
				typeId:'',
				last_page:1,
				height: this.$utils.height(),
				isTriggered: false, //定义一个用来表示下拉刷新是否被触发，当更新完数据需要重新定义为false
				keyword:''
			};
		},
		components: {
			vvSelect,
		},
		onLoad() {
			// this.getOrderList()
			console.log(this.image,'list')
		},
		onReady() {
			this.height = uni.getSystemInfoSync().windowHeight - 22 + 'px';
		},
		onShow(){
			this.tabList = []
			this.page = 1
			this.isText = ''
			this.getOrderList()
		},
		methods: {
			searchProtect(e){
				this.getOrderList()
				// console.log(e.detail.value,'525555555555')
				// this.keyword = e.detail.value
			},
			// searchIcon(){
			// 	this.getOrderList()
			// },
			lower: function(e) {
				// if (this.form.page < this.last_page) {
				// 	this.form.page = this.form.page + 1
					
				// 	// this.projectList()
				// }
			},
			upper: function(e) {
				// console.log('到达顶部吧')
			},
			onPulling(e) {
				if (e.detail.deltaY < 0) return // 防止上滑页面也触发下拉
				this.isTriggered = true;
				// console.log("onpulling", e);
			},
			onRefresh() {
				// console.log("自定义下拉刷新被触发");
				this.closeSel()
				this.isTriggered = false;
			},
			// 获取列表
			getOrderList(){
				let that = this
				that.tabList=[]
				that.$api.protectDeviceList({
					pageNum: that.page,
					keyword: that.keyword
				}).then(res => {
					res.data.rows.length == 0 ? that.isText = '暂无数据' : that.isText = ''
					that.tabList = that.tabList.concat(res.data.rows)
					if(that.tabList.length != 0 ){
						that.tabList = that.tabList.map(item => {
							return {
								...item,
								principleImgUrl:(item.principleImgUrl||'').split(',')
							}
						})
					}
					
					
					console.log(that.tabList,'that.tabList')
					that.last_page = Math.ceil(res.data.total/res.data.rows.length)
					// console.log(res.data.rows,'this.last_page')
				})
			},
			// 点击提货
			pickUpGoods(el){
				let that = this
				uni.showModal({
				 title:  "确定是否提货",
				 success: function (res) {
					  if (res.confirm) {
							that.$api.orderTh({
							 	order_number: el.order_number,
							}).then(res => {
							 	console.log(res)
								that.goDetails(el)
							})
					    } else{
							 console.log('用户点击取消');
					    }
					}
				});
				
			},
			// 点击回购
			buyBack(el){
				let that = this
				uni.showModal({
					 title:  "确定是否回购",
					 success: function (res) {
						if (res.confirm) {
							 console.log('用户点击确定');
							 that.$api.orderHg({
								order_number: el.order_number,
							 }).then(res => {
								console.log(res)
								that.goDetails(el)
							 }) 
						} else{
							 console.log('用户点击取消');
						}
					}
				});
			},
			
			// 跳转到详情页面
			goDetails(el){
				let res = {
					order_number: el.order_number,
					goods_img: el.goods_img,
					goods_name: el.goods_name
				}
				uni.navigateTo({
					url: '/pages/order/details/details?res=' + JSON.stringify(res)
				})
			}
		},
		onReachBottom() {
			let that = this
			if (that.page < that.last_page) {
				that.page = that.page + 1
				that.getOrderList()
			}
		}
		
	}
</script>

<style lang="less">
		
	.u-content{
		border-radius: 10rpx;
	}
	page{
		background-color: #f9f9f9;
	}
	.u-tab-bar{
		display: none !important;
	}
	.list{
		width: 100%;
		height: auto;
		padding: 20rpx;
		border-radius: 20rpx;
		background-color: #fff;
		margin: 20rpx auto;
			
		.rece{
			width: 22%;
			height: 60rpx;
			background: #979797;
			color: #fff;
			text-align: center;
			line-height: 60rpx;
			border-radius: 6rpx;
			margin-top: 80rpx;
		}

		.list_b{
			font-size: 28rpx;
			font-weight: 400;
			color: #7F8084;
			padding-top: 30rpx;
			.text{
				.money{
					display: inline-block;
					font-size: 32rpx;
					font-weight: 600;
					color: #000;
				}
			}
		}
		
		.btnBox{
			width: 100%;
			margin-top: 30rpx;
			flex-direction: row-reverse !important;
			.btn{
				width: 132rpx;
				height: 46rpx;
				line-height: 46rpx;
				border-radius: 46rpx;
				text-align: center;
				background-color: #000;
				color: #fff;
				font-size: 24rpx;
				font-weight: 500;
			}
		}
		
	}
	.serchView {
		width: 100%;
		height: 120rpx;
		display: flex;
		flex-direction: column;
		background-color: #FFFFFF;
		align-items: center;
		justify-content: center;
	}
	.serch {
		width: 690rpx;
		height: 80rpx;
		// background: #F7F7F7;
		border-radius: 20rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
	}
	 
	.serchIconImage {
		width: 32rpx;
		height: 32rpx;
		margin-left: 30rpx;
	}
	 
	.serchInput {
		height: 70rpx;
		width: 600rpx;
		margin-left: 12rpx;
		font-size: 30rpx;
		color: #000000;
	}
	.chooseCup {
		margin-right: 8rpx !important;
	
		image {
			width: 20rpx !important;
			height: 12rpx !important;
			margin: 14rpx;
		}
	}
	.order{
		width: 100vw;
		.tabBox{
			width: 100%;
			// height: 100rpx;
		}
		.listBox{
			width: 100%;
			// margin: 30rpx 0;
			// padding: 0 30rpx;
			// background: rebeccapurple;
			// height: 600rpx;
			.list{
				width: 100%;
				height: auto;
				padding: 20rpx 30rpx;
				border-radius: 20rpx;
				background-color: #fff;
				margin: 20rpx auto;
				.code{
					color: #000;
					font-weight: 400;
					font-size: 12px;
					line-height:80rpx;
					height: 80rpx;
					// margin-bottom: 10rpx;
					.title{
						width: 36%;
					}
					.content{
						width: 63%;
						color: #979797;
						white-space: nowrap; 
						overflow: hidden;
						text-overflow: ellipsis;

					}
				}
				.pic{
					width: 200rpx;
					height: 200rpx;
					margin: 14rpx;
					image{
						width: 100%;
						height: 100%;
					}
				}
				.line{
					width: 100%;
					height: 2rpx;
					background: #f0f0f0;
					margin: 0 auto;
				}
				.list_b{
					font-size: 28rpx;
					font-weight: 400;
					color: #7F8084;
					padding-top: 30rpx;
					.text{
						.money{
							display: inline-block;
							font-size: 32rpx;
							font-weight: 600;
							color: #000;
						}
					}
				}
				
				.btnBox{
					width: 100%;
					margin-top: 30rpx;
					flex-direction: row-reverse !important;
					.btn{
						width: 132rpx;
						height: 46rpx;
						line-height: 46rpx;
						border-radius: 46rpx;
						text-align: center;
						background-color: #000;
						color: #fff;
						font-size: 24rpx;
						font-weight: 500;
					}
				}
				
			}
		}
	}
</style>
